-- card: 44247 from stack: in.3r -- bmap block id: 0 -- flags: 0000 -- background id: 13187 -- name: ChangeObjectLayer -- part contents for background part 4 ----- text ----- 7 -- part contents for background part 18 ----- text ----- Scripts -- part contents for background part 2 ----- text ----- ChangeObjectLayer -- part contents for background part 3 ----- text ----- About "ChangeObjectLayer" 1.0... •You've heard of ShareWare and FreeWare! I now introduce TradeWare!!! This script is TradeWare. If you find it useful, send me an 800K floppy packed with ShareWare and FreeWare goodies; I am especially interested in HyperCard development tools and utilities (such as XCMD/XFCNs, etc.—I already have the Developer Stack, Thank You), and system tools and utilities (INITs and CDEVs, etc). In return, I will send your disk back to you with ShareWare and FreeWare goodies from my own collection. No sound stacks, please—they're too obnoxious, and wasteful of disk space and memory. Please send neat (and/or useful) stuff to: Dean H. Wette 921 DeMun Avenue 2N Clayton, MO 63105 314-863-4944 •Now...finally...about ChangeObjectLayer... While developing a stack containing numerous modal popup dialogs, fields, and buttons, I found myself constantly going to the "Objects" menu for the "Send Farther" and "Bring Closer" commands in order to move objects (buttons and fields) through different card and background layers. In some cases I wanted to obscure other objects, and in other cases I wanted to prevent objects from being obscured. Well, anyway, when you have 20 or more each of background and card buttons and fields, this menu selection (or its command key equivalent) business to change object layers can become quite tedious and boring. Therefore, I developed "ChangeObjectLayer" to automate and speed-up the process of moving objects' through different layers. "ChangeObjectLayer" works with both card and background buttons and fields. Try it out! On this card are six each of card and background buttons and fields. See the effect of changing a card/background button/field from 6 to 1 and vice versa. •To install ChangeObjectLayer functions 1) Copy the handler "setLayer" and the function "theLayer" plus the two utility handlers "setLocksTrue" and "setLocksFalse." 2) Paste everything into a card, background, or stack script. The best place for the "ChangeObjectLayer" scripts and the "setLocks" scripts is in the stack script of your Home stack, thus making the script available in all stacks. •To invoke "ChangeObjectLayer" do the following: 1) Open the script editing window of the object (button or field) you want to change. 2a) If the object contains a script then add "setLayer" (with-out the quotes) as the second line of the objects script—the line following "on mouseUp." The part of the script following "setLayer" will be disabled until you remove the call to "setLayer." 2b) If the object does not already have a script then type the following script in the script editing window: on mouseUp setLayer end mouseUp 3) Click "OK" to close the editing window and then click on the object (make sure the browse tool is selected). Note: if the object is a field, then the lockText property must be set to true (i.e. lock the field) for "ChangeObjectLayer" to work. 4) You will be prompted to specify the number to which the object will be set. The prompt will indicate the valid range (e.g. "1-6" - you can't set a card button to 'card button 7' if there are only 6 card buttons). Enter a valid number, click "OK", and wait. "ChangeObjectLayer" will beep three times when it finished with its task. 5) Remove the "setLayer" line from the object script to reenable any original object script. If the "setLayer" call is the second line of the object's script, it will be removed for you. [Hey Bill, can we fix the orphan quotes and parentheses?!?!] •Notes: The "setLayer" handler concludes with an "exit to HyperCard" command so if you call it from an existing handler in a button or field, any script folowing the call will not execute until you remove the "setLayer" line of your object script. Sometimes, when an object is set to its highest or lowest number it may still obscure—or be obscured—by an object of its unlike type (field/button or vice versa). To remedy this, you may need to invoke "Send Farther" or "Bring Closer" additional times (i.e. use "Bring Closer" when an object is at its highest number already, or "Send Farther" when it is at its lowest number). This can be accomplished with "ChangeObjectLayer". [Those damn orphan quotes again!] If you hold down the optionkey while invoking the "setLayer" handler from an object, you can enter an invalid object number (such as 0 or 1,000,000). This will cause "ChangeObjectLayer" to invoke the "Send Farther" or "Bring Closer" menu commands forever. Press Command-. (period) to stop the repeated execution, and press Command-Tab to select the browse tool. The "setLayer" handler can be invoked once again in similar manner if necessary. •Well, that's about it for "ChangeObjectLayer" 1.0. I wrote and tested it on Friday, July, 29, 1988. If you find any bugs or have suggestions for improvements please let me know (no collect calls please). Happy setLayering! --ChangeObjectLayer 1.0 --©1988 by Dean H Wette --921 DeMun Avenue 2N --Clayton, MO 63105 --314-863-4944 --Please include the above credits with the script. --This script is TradeWare. See above --for more information and instructions. ------------------------------------------------------------------------ --The best place for these scripts is in the Home stack, thus --making "ChangeObjectLayer" available to all your stacks. --Begin ChangeObjectLayer 1.0 --This is the handler called by the target object. --The call, "setLayer", should be the second line --of the object's script, after "on mouseUp". on setLayer global objectNumber,objectType,optionState put the optionKey into optionState --We need information about the target object — get it from --the "objectInfo" function. put objectInfo() into doMenuWhich setLocksTrue -- Don't forget to include the "setLocks" handlers! --Go from the browse tool to the object's editing tool --and select the object. if objectType = "button" then choose btn tool else choose fld tool select the target --This is where the work gets done. repeat until the number of the target = objectNumber set cursor to busy --Find out if the object goes to a higher or lower layer, or --if it's all just a waste of time. if doMenuWhich < 0 then doMenu "Send Farther" if doMenuWhich > 0 then doMenu "Bring Closer" if doMenuWhich = 0 then exit repeat end repeat beep 3 --We're finished so let's clean up & return everything to normal. set cursor to 4 choose browse tool setLocksFalse put empty into objectNumber put empty into objectType put empty into optionState --Let's remove the "setLayer" call for the user, that is, --if it's in the right place! if line 2 of script of target contains "setLayer" then put script of target into objectScript put empty into line 2 of objectScript set script of target to objectScript else end if --We just want to change the object's layer so let's not --execute its normal script exit to HyperCard end setLayer --This is the function that returns all the object information --needed to allow "setLayer" to perform properly. function objectInfo global objectNumber,objectType,optionState --Is the Object a field or a button? if the name of the target contains "field" then put "field" into objectType else put "button" into objectType end if --Is the object a card or background object? if the name of the target contains "bkgnd" then put "bkgnd" into objectClass else put "card" into objectClass end if --What is the object's current number? put the number of the target into fromThis --What is the highest possible number of the object if objectType = "button" then if the name of the target contains "bkgnd" then put the number of last bg btn into theRange else put the number of last btn into theRange end if else if objectType = "field" then if the name of the target contains "card" then put the number of last cd field into theRange else put the number of last field into theRange end if end if end if --Now we know the object's possible range. --This is the function part of the function. It returns --the target number of the object. --Prompt the user for a target object number --& give the valid range of numbers. ask "Set " &objectClass &&objectType &&fromThis && ¬ "to what number? (1-" &theRange &")" if it is empty then exit to HyperCard set cursor to 4 put it into objectNumber --If user holds down option key while invoking "setLayer" --then the following error checking is bypassed. if optionState is up then --Error checking...make sure the user enters a valid number. if objectNumber > theRange or objectNumber < 1 then beep answer "Sorry! “" &objectNumber &"” is not a valid "¬ &objectType &&"number." exit to HyperCard else end if end if --Now we have the target number and information we need to proceed. return objectNumber - fromThis end objectInfo --end ChangeObjectLayer 1.0 ------------------------------------------------------------------------ --These two utility handlers are called by "ChangeObjectLayer," --so make sure you include them. I did not write these handlers, --and I can't remember where I got them. My apologies to whoever --deserves due credit for "setLocks". --This one locks everything! on setLocksTrue lock screen set lockRecent to true set lockMessages to true end setLocksTrue --This one unlocks everything! on setLocksFalse unlock screen set lockRecent to false set lockMessages to false end setLocksFalse --YOU NEED ALL THE ABOVE SCRIPTS FOR "CHANGEOBJECTLAYER" TO WORK!!!